package com.woniuxy.house.admin;

import com.woniuxy.house.entity.Booking;
import com.woniuxy.house.service.BookingService;
import com.woniuxy.house.utils.JwtUtil;
import com.woniuxy.house.vo.ResponseEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController("adminbookingcontroller")
@RequestMapping("/booking")
public class BookingController {

    @Autowired
    private JwtUtil jwtUtil;

    @Autowired
    private BookingService bookingService;

    @RequestMapping("/list")
    public ResponseEntity list(@RequestHeader String jwt) {
        if (jwtUtil.verifyJWT(jwt)) {
            return new ResponseEntity("200", "OK", bookingService.getAll());
        } else {
            return new ResponseEntity("700", "令牌失效", "null");
        }
    }

    @RequestMapping("/update")
    public ResponseEntity update(@RequestBody Booking booking){
        bookingService.updateBooking(booking);
        return ResponseEntity.SUCCESS;
    }

    @RequestMapping("/delete")
    public ResponseEntity datele(@RequestBody Booking booking){
        bookingService.updateBooking(booking);
        return ResponseEntity.SUCCESS;
    }
}
